<?php

namespace app\apiweb\controller;

use app\admin\model\cases\Ctype;
use app\apishop\validate\ComplaintValidate;
use app\common\controller\Api;
use think\Config;
use think\Exception;

/**
 * 商户投诉信息表
 */
class Complaint extends Api
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = '*';

    protected $failException = true;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\shop\Complaint();
        $this->modelType = new Ctype();
        $this->modelUser = new \app\admin\model\shop\User();
        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }
    }




    /**
     * 举报
     * @return void
     */
    public function submit()
    {
        $input = input('post.');
        try {
            $this->validate($input, \app\apiweb\validate\ComplaintValidate::class . '.submit');
            if ($input['type'] == 1){
                if (empty($input['username'])){
                    throw new Exception('请填写姓名');
                }
                if (empty($input['username_mobile'])){
                    throw new Exception('请填写手机号');
                }
            }
            $input['type'] = 2;
            $this->model->insert($input);
            $this->success('投诉成功');
        } catch (Exception $e) {
            $this->error($e->getMessage());
        }
    }


}